package cn.edu.hit.selflearning;

import cn.edu.hit.kg.data.GraphData;
import cn.edu.hit.kg.entity.Fault;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


public class GetExplain {

    static GraphData graphData = GraphData.getInstance();

    public static JSONObject getExplain(Long faultId, String machineNo) {
        JSONObject jsonObject = new JSONObject();
        Fault fault = Fault.loadById(faultId);
        String matchii = fault.getMatchedFeature(machineNo);
        JSONArray array2 = JSONArray.fromObject(matchii);
        jsonObject.put("match", array2);
        List<Long> ids = graphData.getAllSubNodeIds(faultId).collect(Collectors.toList());
        for (int i = 0; i < ids.size(); i++) {
            jsonObject.put(ids.get(i), graphData.getById(ids.get(i)).asMap());
            jsonObject.put("edges" + ids.get(i), graphData.getAllSubNodeIds(ids.get(i)).collect(Collectors.toList()));
        }
        return jsonObject;
    }


    public static void main(String[] args) {


        getExplain((long) 2693, "030100103");
//        Fault a = Fault.loadById(2693);
//
//        String matchii = a.getMatchedFeature("030100103");
//
//        System.out.println(matchii);
//
//
//        JSONArray array = JSONArray.fromObject(matchii);
//
//        for (int i = 0; i < array.size(); i++) {
////            graphData.getAllSubNodes(array.getInt(i));
//
//            List<Map> featureList = graphData.getAllSubNodes(array.getInt(i))
////                    .filter(node -> node.hasLabel("Feature"))
//                    .map(node -> node.asMap())
//
//                    .collect(Collectors.toList());
//
//
//            System.out.println(featureList);
//
//        }
//        Map edges = graphData.getEdges();
//
//        edges.get("3320");
//
//        System.out.println(edges);

//        List<Long> idList = graphData.getAllSubNodeIds(2693).collect(Collectors.toList());
//
//        System.out.println(idList);
//


    }
}
